/*
 * 文件名：ExpUserController.java
 * 版权：Copyright 2006-2013 lvxh Tech. Co. Ltd. All Rights Reserved. 
 * 描述： ExpUserController.java
 * 修改人：lxh
 * 修改时间：2013年9月26日
 * 修改内容：新增
 */
package com.lvxh.exp.office.controller;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.lvxh.exp.bean.BaseController;
import com.lvxh.exp.bean.GridResultHolder;
import com.lvxh.exp.office.bean.SourceFileBean;
import com.lvxh.exp.sequence.dao.holder.Sequence;
import com.lvxh.exp.sequence.service.SequenceService;
import com.lvxh.exp.system.util.ExpUtils;

/**
 * TODO 添加类的一句话简单描述。
 * <p>
 * TODO 详细描述
 * <p>
 * TODO 示例代码
 * 
 * <pre>
 * </pre>
 * 
 * @author lxh
 * @version expweb 1.0.0 2013年9月26日
 * @since expweb 1.0.0
 */
@RequestMapping("/knowledge")
@Controller
public class ExpKnowledgeController extends BaseController
{
    /**
     * 调测日志记录器。
     */
    private static final Logger log = Logger.getLogger(ExpKnowledgeController.class);

    @Autowired
    SequenceService sequenceService;
    
    @RequestMapping("/java")
    public ModelAndView initJava()
    {
        log.debug("start method  knowledge");
        List <SourceFileBean> list = new ArrayList<SourceFileBean>();
        String filePath = "D:/lxh/expsource/java";
        File files[] = new File(filePath).listFiles();
        for(int i=0;i<files.length;i++)
        {
            SourceFileBean bean = new SourceFileBean();
            bean.setTitle(files[i].getName().split("\\.")[0]);
            bean.setContent(ExpUtils.getFileContext(files[i].getPath()));
            bean.setFilePath(files[i].getPath());
            list.add(bean);
        }
        Map<String,List<SourceFileBean>>map = new HashMap<String,List<SourceFileBean>>();
        map.put("sourceFile", list);
        return new ModelAndView("document/java",map);

    }
    @RequestMapping("/mysql")
    public ModelAndView initSql()
    {
        log.info("start method  initSql");
        return new ModelAndView("document/sql");

    }
    
    @RequestMapping("/getGridSql")
    @ResponseBody
    public GridResultHolder getGridSql(Sequence seq,String seqname)
    {
        log.info("start method  initSql");
        int count =sequenceService.getCountOfSummary(seq);
        int sum = procesPage(seq, count);
        GridResultHolder result = new GridResultHolder();
        result.setResult(sequenceService.getListOfSummary(seq));
        result.setPageCount(sum);
        return result;

    }
    
}
